Component({
  /**
   * 组件的属性列表
   */
  properties: {
    dataTree: {
      type: Array,
      value: [],
    },
    selectItem: {
      // 选中的节点id
      type: Object,
      value: {},
    },
    isSelectLastNode: {
      //是否必须选中最后一节点
      type: Boolean,
      value: false,
    },
    isOpenAll: {
      //是否展开全部节点
      type: Boolean,
      value: false,
    },
  },
  observers: {
    dataTree: function (params) {
      // params.forEach((v) => {
      //   v.open = this.properties.isOpenAll; // 是否展开
      // });
      this.setData({
        tree: params,
      });
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    tree: [],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    isOpen(e) {
      const open = "tree[" + e.currentTarget.dataset.index + "].open";
      const openItem = e.currentTarget.dataset.item;

      //事件传递
      this.triggerEvent(
        "treeOpenEvent",
        { openItem: openItem },
        { bubbles: true, composed: true }
      );
    },
    select(e) {
      const item = e.currentTarget.dataset.item;
      if(!item.hasOrgPermission){
        return false
      }
      const selectedTypePath =
        "tree[" + e.currentTarget.dataset.index + "].selectedType";
      const selectedType =
        this.data.tree[e.currentTarget.dataset.index].selectedType;
      const selectItem = {
        id: item.id,
        treeId: item.treeId,
        selectedType: item.selectedType,
      };

      //事件传递
      this.triggerEvent(
        "treeSelectEvent",
        { selectItem: selectItem },
        { bubbles: true, composed: true }
      );
    },
  },
});
